/*
  Copyright � 2009 Smart Enterprise Solution Corp.
  Email: contact@ses.vn - Website: http://www.ses.vn
  ThanhNam ERP Project.
*/
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using VINETLIFE.DO;
/// <summary>
/// Summary description for cmsSytemStatusDAL
/// </summary>
namespace VINETLIFE.DAL
{

    public class cmsSytemStatusDAL : BaseDAL
    {
        #region Private Variables

        #endregion

        #region Public Constructors
        public cmsSytemStatusDAL()
        {
            //
            // TODO: Add constructor logic here
            //

        }
        #endregion



        #region Public Methods
        public int Insert(cmsSytemStatusDO objcmsSytemStatusDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSytemStatus_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@SystemStatus", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsSytemStatusDO.SystemStatus;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@SystemStatusText", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsSytemStatusDO.SystemStatusText;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Note", SqlDbType.NText);
            Sqlparam.Value = objcmsSytemStatusDO.Note;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@OrderId", SqlDbType.Int);
            Sqlparam.Value = objcmsSytemStatusDO.OrderId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CreatedDate", SqlDbType.DateTime);
            Sqlparam.Value = objcmsSytemStatusDO.CreatedDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CreatedById", SqlDbType.Int);
            Sqlparam.Value = objcmsSytemStatusDO.CreatedById;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Type", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsSytemStatusDO.Type;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);


            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(cmsSytemStatusDO objcmsSytemStatusDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSytemStatus_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@SystemStatus", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsSytemStatusDO.SystemStatus;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@SystemStatusText", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsSytemStatusDO.SystemStatusText;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Note", SqlDbType.NText);
            Sqlparam.Value = objcmsSytemStatusDO.Note;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@OrderId", SqlDbType.Int);
            Sqlparam.Value = objcmsSytemStatusDO.OrderId;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CreatedDate", SqlDbType.DateTime);
            Sqlparam.Value = objcmsSytemStatusDO.CreatedDate;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@CreatedById", SqlDbType.Int);
            Sqlparam.Value = objcmsSytemStatusDO.CreatedById;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Type", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsSytemStatusDO.Type;
            Sqlcomm.Parameters.Add(Sqlparam);


            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);

            return result;


        }

        public int Delete(cmsSytemStatusDO objcmsSytemStatusDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSytemStatus_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@SystemStatus", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsSytemStatusDO.SystemStatus;
            Sqlcomm.Parameters.Add(Sqlparam);



            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public int DeleteAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSytemStatus_DeleteAll";

            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public cmsSytemStatusDO Select(cmsSytemStatusDO objcmsSytemStatusDO)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSytemStatus_GetByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@SystemStatus", SqlDbType.NVarChar);
            Sqlparam.Value = objcmsSytemStatusDO.SystemStatus;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["SystemStatus"]))
                    objcmsSytemStatusDO.SystemStatus = Convert.ToString(dr["SystemStatus"]);
                if (!Convert.IsDBNull(dr["SystemStatusText"]))
                    objcmsSytemStatusDO.SystemStatusText = Convert.ToString(dr["SystemStatusText"]);
                if (!Convert.IsDBNull(dr["Note"]))
                    objcmsSytemStatusDO.Note = Convert.ToString(dr["Note"]);
                if (!Convert.IsDBNull(dr["OrderId"]))
                    objcmsSytemStatusDO.OrderId = Convert.ToInt32(dr["OrderId"]);
                if (!Convert.IsDBNull(dr["CreatedDate"]))
                    objcmsSytemStatusDO.CreatedDate = Convert.ToDateTime(dr["CreatedDate"]);
                if (!Convert.IsDBNull(dr["CreatedById"]))
                    objcmsSytemStatusDO.CreatedById = Convert.ToInt32(dr["CreatedById"]);
                if (!Convert.IsDBNull(dr["Type"]))
                    objcmsSytemStatusDO.Type = Convert.ToString(dr["Type"]);

            }
            return objcmsSytemStatusDO;
        }

        public ArrayList SelectAll1()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSytemStatus_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrcmsSytemStatusDO = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    cmsSytemStatusDO objcmsSytemStatusDO = new cmsSytemStatusDO();
                    if (!Convert.IsDBNull(dr["SystemStatus"]))
                        objcmsSytemStatusDO.SystemStatus = Convert.ToString(dr["SystemStatus"]);
                    if (!Convert.IsDBNull(dr["SystemStatusText"]))
                        objcmsSytemStatusDO.SystemStatusText = Convert.ToString(dr["SystemStatusText"]);
                    if (!Convert.IsDBNull(dr["Note"]))
                        objcmsSytemStatusDO.Note = Convert.ToString(dr["Note"]);
                    if (!Convert.IsDBNull(dr["OrderId"]))
                        objcmsSytemStatusDO.OrderId = Convert.ToInt32(dr["OrderId"]);
                    if (!Convert.IsDBNull(dr["CreatedDate"]))
                        objcmsSytemStatusDO.CreatedDate = Convert.ToDateTime(dr["CreatedDate"]);
                    if (!Convert.IsDBNull(dr["CreatedById"]))
                        objcmsSytemStatusDO.CreatedById = Convert.ToInt32(dr["CreatedById"]);
                    if (!Convert.IsDBNull(dr["Type"]))
                        objcmsSytemStatusDO.Type = Convert.ToString(dr["Type"]);
                    arrcmsSytemStatusDO.Add(objcmsSytemStatusDO);
                }
            }
            return arrcmsSytemStatusDO;
        }

        public DataTable SelectAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSytemStatus_GetAll";
          
            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }
        public DataTable SelectByType(string type)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "spcmsSytemStatus_GetByType";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@Type", SqlDbType.NVarChar);
            Sqlparam.Value = type;
            Sqlcomm.Parameters.Add(Sqlparam);

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }


        #endregion

    }

}
